<template>
    <el-form :model="loginForm" class="login-container">
        <h3>系统登录</h3>
        <el-form-item>
            <el-input type="input" v-model="loginForm.username" placeholder="请输入账号"></el-input>
        </el-form-item>
        <el-form-item>
            <el-input type="password" v-model="loginForm.password" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="loginHandler">登录</el-button>
            <el-button>取消</el-button>
        </el-form-item>
    </el-form>
</template>


<script setup>
import { reactive } from "vue";
import { loginApi } from '@/service/loginApi.js';
import useStore from '@/store/index.js';
import { useRouter } from 'vue-router';
const router = useRouter()
const store = useStore()
const loginForm = reactive({
    username: 'admin',
    password: 'admin'
})
const loginHandler = async () => {
    let res = await loginApi(loginForm)
    store.setMenu(res.data.menu);
    store.addMenu(router)
    store.setToken(res.data.token)
    router.push({
        name: 'home'
    })
}

</script>


<style lang='scss' scoped>
.login-container {
    width: 350px;
    background-color: #fff;
    border: 1px solid #eaeaea;
    border-radius: 15px;
    padding: 35px 35px 15px 35px;
    box-shadow: 0 0 25px #cacaca;
    margin: 180px auto;

    h3 {
        text-align: center;
        margin-bottom: 20px;
        color: #505450;
    }

    :deep .el-form-item__content {
        justify-content: center;
    }
}
</style>